<?php
/**
* USers Management package.
* This class implements the Users interface for the Client Side. This interface is made up of the
* following actions:
* <ul><li><b>draw</b>: Draw the template for the management panel</li>
* <li><b>delete</b>: Delete a user (must be admin or user himself)</li>
* <li><b>create</b>: Create a new user (must be admin)</li>
* <li><b>list</b>: List all users (will return only myself if i am not admin)</li>
* <li><b>edit</b>: Modify user data (only myself if not admin)</li>
* <li><b>clear</b>: Reset all user permissions</li>
* <li><b>password</b>: Change user password</li>
*</ul>
*@todo Most of this is still to be implemented, waiting for a proper Auth interface.
*@package Management
*@subpackage Users
*@author Willy Gardiol <willy@gardiol.org>
*@version 1.0
*/
class MgmUsers extends MgmRequest
{
	protected $actions = array( "draw" => "DrawTemplate",
								"delete" => "DeleteUser",
								"create" => "CreateUser",
								"list" => "ListUsers",
								"edit" => "EditUser",
								"clear" => "ClearPermissions",
								"password" => "ChangePassword");

	protected function DrawTemplate()
	{
		$template = new HtmlTemplate("core:management_users",
							array(
								));
		$template->DrawHtml();
	}

	protected function DeleteUser()
	{
		$this->SetOutput("result",  CoreAuth::DeleteUser( Core::PostVar("user_id", false, "string") ) );
			
	}

	protected function CreateUser()
	{
		$this->SetOutput("result", CoreAuth::CreateUser(	Core::PostVar("nickname", false, "string"),
							Core::PostVar("fullname", false, "string"),
							Core::PostVar("email", false, "string"),
							Core::PostVar("password", false, "string"),
							Core::PostVar("admin", false, "bool") ) );
	}

	protected function ListUsers()
	{
		$this->SetOutput( "users", CoreAuth::ListUsers() );
	}

	protected function EditUser()
	{
		$this->SetOutput("result", CoreAuth::EditUser( Core::PostVar("user_id", false, "string"),
														Core::PostVar("user_data", false, "unserialize") ) );
	}

	protected function ClearPermissions()
	{
		$this->SetOutput("result", false );
	}

	protected function ChangePassword()
	{
		$this-SetOutput("result", CoreAuth::SetPassword(Core::PostVar("password", false, "string"),
														Core::PostVar("user_id", false, "string") ) );
	}
}
?>
